#include "graph.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn=205;
int d[maxn],col[maxn],idcnt;
int bit[maxn][20];
int fa[maxn],faid[maxn],mk[maxn][maxn],g[maxn][maxn],e[maxn][maxn],cur[maxn][maxn];
int vis[maxn];
void build(int u){
	d[u]=NumberOfRoads();
	fa[u]=LastRoad();
	for(int i=1;i<=d[u];i++){
		if(i==fa[u]) continue;
		Move(i,2);
		int c=Color();
		if(c==1){
			mk[u][i]=++idcnt;
			faid[idcnt]=u;
			build(idcnt);
		}
		else if(c==2) Move(LastRoad(),c);
		else mk[u][i]=-1,Move(LastRoad(),c);
	}
	if(fa[u]!=-1) Move(fa[u],3);
}

void calc(int u){
	for(int i=1;i<=d[u];i++){
		if(!mk[u][i] || mk[u][i]==-1) continue;
		Move(i,col[u]+1);
		calc(mk[u][i]);
	}
	for(int i=1;i<=d[u];i++){
		if(i==fa[u] || mk[u][i]) continue;
		Move(i,col[u]+1);
		int c=Color();
		cur[u][i]=c-1;
		Move(LastRoad(),c);
	}
	if(fa[u]!=-1) Move(fa[u],col[u]+1);
}
int cnt[maxn],dis[maxn][maxn];
void Inspect(int R){
    build(++idcnt);
	for(int i=1;i<=idcnt;i++){
		int bcnt=0,v=i;
		while(v){
			bit[i][++bcnt]=v%3;
			v/=3;
		}
	}
	for(int k=5;k>=1;k--){
		for(int i=1;i<=idcnt;i++){
			col[i]=bit[i][k];
		}
		calc(1);
		for(int i=1;i<=idcnt;i++){
			for(int j=1;j<=d[i];j++){
				if(mk[i][j] || j==fa[i]) continue;
				g[i][j]=g[i][j]*3+cur[i][j];
			}
		}
	}
	for(int i=1;i<=idcnt;i++){
		for(int j=1;j<=idcnt;j++){
			dis[i][j]=idcnt+1;
		}
	}
	for(int i=1;i<=idcnt;i++){
		dis[i][i]=0;
	}
	for(int i=1;i<=idcnt;i++){
		for(int j=1;j<=d[i];j++){
			if(mk[i][j]==-1) continue;
			if(mk[i][j]) e[i][mk[i][j]]=1;
			else if(j==fa[i]) e[i][faid[i]]=1;
			else e[i][g[i][j]]=1,e[g[i][j]][i]=1;
		}
	}
	for(int i=1;i<=idcnt;i++){
		memset(vis,0,sizeof vis);
		queue<int> q;
		q.push(i);
		vis[i]=1;
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int j=1;j<=idcnt;j++){
				if(e[u][j]==1 && !vis[j]){
					vis[j]=1;
					dis[i][j]=dis[i][u]+1;
					q.push(j);
				}
			}
		}
	}
	for(int i=1;i<=idcnt;i++){
		for(int j=i+1;j<=idcnt;j++){
			cnt[dis[i][j]]++;
		}
	}
	for(int i=1;i<=R;i++){
		Answer(i,cnt[i]);
	}
}
